#include<fcntl.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>

int main()
{
    const char *str1 = "Hello World!";
    const char* filename = "a.txt";

    int fd = open(filename, O_CREAT | O_RDWR|O_APPEND);
    if(fd == -1)
    {
        perror("fd:文件打开失败");
        return -1;
    }

    int ret = write(fd, str1, strlen(str1));
    if(ret == -1)
    {
        perror("文件写入失败");
        return -1;
    }

    int copy_fd = dup(fd);
    const char* str2 =  "Linux is an open source OS.";
    ret = write(copy_fd, str2, strlen(str2));
    if(ret == -1)
    {
        perror("copyfd:文件写入失败");
        return -1;
    }

    return 0;
}